#!/usr/bin/env python
# -*- coding: utf-8; py-indent-offset:4 -*-

# @Time    :2023/05/03 16:10:31
# @Author  :wakeblade (2390245#qq.com) 
# @version :8.1

"""
scan.py -- 
"""

import time
import socket
import threading

#检测soket是否连接成功或失败
def test_port(ip,port):
    cli_sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    cli_sock.settimeout(2)
    try:
        # 使用socket模块进行尝试连接
        indicator = cli_sock.connect_ex((ip, port))
        if indicator == 0:#如果连接成功，输入连接信息，并将结果写入文件中
            print("[+]" + str(ip) + "  " + str(port) + " Open")
            # time.sleep(5)
        else:#如果连接失败，输入连接信息
            pass
            # print("[-]" + str(ip) + "  " +str(port) + " Close")
        cli_sock.close()
    except:
        pass

def test_ip(ip):
    for port in range(20, 65536):
        threading.Thread(target=test_port, args=(ip,port)).start()
    
# test_ip("www.jobees.cn")
# test_ip("43.134.198.247")
test_ip("192.168.18.1")